<template>
  <div class="vH">
    <mei-tree
      ref="a2tree"
      :showsearch="false"
      :data="data.TreeData"
      idKey="ASSET_A2_AUTOID"
      pIdKey="ASSET_A2_PARENTID"
      nameKey="ASSET_A2_10"
      @current-change="onNodeClick"
    ></mei-tree>
  </div>
</template>

<script>
import { AssetA2 } from "@/api";
export default {
  data() {
    return {
      //页面控制
      page: {},
      //数据
      data: {
        TreeData: [] //资产分类数据
      }
    };
  },
  inject: ["AssetA1"],
  //外部属性
  props: {},
  //内部方法
  methods: {
    initPage() {
      this.getAssetA2();
    },
    async getAssetA2() {
      let search = {
        assetquery: this.AssetA1.data.assetquery
      };
      this.data.TreeData = await AssetA2.get(search);
    },
    onNodeClick(rowdata) {
      //id集合
      let nodeids = [];
      //获得所有的子id （节点数据）
      let getnodeids = node => {
        nodeids.push(node.ASSET_A2_AUTOID);
        //如果有子节点
        if (node.children.length != 0) {
          node.children.forEach(item => {
            getnodeids(item);
          });
        }
      };
      getnodeids(rowdata);
      //触发事件
      this.$emit("onNodeClick", nodeids, rowdata);
    }
  },
  //组件
  components: {},
  //初始化 异步加async await
  mounted() {
    this.initPage();
  },
  //计算属性
  computed: {},
  //监视
  watch: {}
};
</script>

<style lang="scss" scoped>
@import "@/style/base.scss";
</style>
